package loadgen;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MemoryStresser {

	Logger logger = Logger.getLogger(MemoryStresser.class.getCanonicalName());
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		new MemoryStresser().generateLoad(3000);		
	}
	
	/**
	 * Allocates memory with an ArrayList.
	 * @param timeout The time in milliseconds to hold allocated data in memory.
	 */
	public void generateLoad(int timeout)
	{
		ArrayList<Long> longArray = new ArrayList<Long>();
		
		for(long i = 0; i < 500000; i++)
		{
			longArray.add(i);
		}
		
		try {
			Thread.sleep(timeout);
		} catch (InterruptedException e) {			
			logger.log(Level.SEVERE, "Interrupted memory load generation: ", e);
		}
		
		longArray.clear();
		longArray = null;
		System.gc();
	}

}
